<!DOCTYPE HTML>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.Iterator"%>
<%@page import="shop.factory.DAOFactory"%>
<%@page import="java.util.List"%>
<%@page import="shop.vo.ProductBean"%>
<html>
<head>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<meta charset="utf-8">
<link rel="stylesheet" href="../css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="css/car.css" />
<script src="js/cat.js" type="text/javascript" charset="utf-8"></script>
<script src="../js/jquery-1.10.2.min.js" type="text/javascript"
	charset="utf-8"></script>
<script type="text/javascript" src="../js/bootstrap.min.js"></script>
<!--<meta name="viewport" content="width=device-width, initial-scale=1">-->
<!--[if lt IE 9]>
      	<script src="http://cdn.bootcss.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      	<script src="http://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
    	<![endif]-->
<title>购物车</title>
</head>
<%
	if (session.getAttribute("product") == null) {
		List<ProductBean> a = new ArrayList<ProductBean>();
		session.setAttribute("product", a);
	} else {
		
	}
	List<ProductBean> li = (List<ProductBean>)session.getAttribute("product");
%>
<body>
	<nav class="navbar navbar-default" role="navigation">
		<div class="navbar-header">
			<button type="button" class="navbar-toggle" data-toggle="collapse"
				data-target="#bs-example-navbar-collapse-1">
				<span class="sr-only">Toggle navigation</span> <span
					class="icon-bar"></span> <span class="icon-bar"></span> <span
					class="icon-bar"></span>
			</button>
		</div>
		<div class="collapse navbar-collapse"
			id="bs-example-navbar-collapse-1">
			<ul class="nav navbar-nav">
				<li class="active"><a href="../index.jsp">首页</a></li>
				<li><a href="<%=request.getContextPath() %>/OrderServlet?action=MyOrder"> <img src="../images/order.png" /> 我的订单
				</a></li>
				<li></li>
				<li><a href="<%=request.getContextPath() %>/OrderServlet?action=MyCart"> <img src="../images/car.png" /> 我的购物车
				</a></li>
				<li><a href="<%=request.getContextPath() %>/FavoriteServlet?action=MyFav"> <img src="../images/favorite.png" /> 我的收藏
				</a></li>
				<li><a href="<%=request.getContextPath() %>/AddressServlet?action=MyAddress"> <img src="../images/address.png" /> 我的地址簿
				</a></li>
			</ul>

			<ul class="nav navbar-nav navbar-right">
				<li><a href="<%=request.getContextPath() %>/UserServlet?action=xinxi"><span id="huanying">欢迎光临，游客</span></a></li>
				<li><a href="../Login/login.jsp">登陆</a></li>
				<li><a href="../Login/regist.jsp">注册</a></li>
				<li><a href="<%=request.getContextPath() %>/UserServlet?action=logout" class="active" onclick="return confirm('确认退出?')">退出</a></li>
			</ul>
		</div>
	</nav>
	<div class="container" style="height: 600px;">
		<div class="col-md-4">
			<img src="../images/logo.png" />
		</div>

		<div class="col-md-12 cartitlle">我的购物车</div>
		<div class="col-md-12 table-responsive">
		<form action="<%=request.getContextPath()%>/ProductServlet" method="post">
		<input type="hidden" name="action" value="jiesuan">
			<table id="cartTable" class="table  table-bordered">
				<thead>
					<tr>
						<th><label> <input class="check-all check"
								type="checkbox" />&nbsp;&nbsp;全选
						</label></th>
						<th>商品</th>
						<th>单价</th>
						<th>数量</th>
						<th>小计</th>
						<th>操作</th>
					</tr>
				</thead>
				<tbody>
					<%
					for (int i = 0;i < li.size();i ++) {
					//	li.get(i);
						List<ProductBean> list = DAOFactory.getIProductDAOInstance().xiangqing(li.get(i));
						Iterator<ProductBean> it = list.iterator();
						if (it.hasNext()) {
							ProductBean product1 = it.next();
					%>
					<tr>
						<td class="check"><input class="check-one check"
							type="checkbox" name="checkbox" value="<%=product1.getPro_id()%>"/></td>
						<td class="goods"><img src="../<%=product1.getPro_litlleimg() %>" alt="" /><a
							href="<%=request.getContextPath()%>/ProductServlet?action=xiangqing&proId=<%=product1.getPro_id()%>"><%=product1.getPro_name() %></a><span></span></td>
						<td class="price"><%=product1.getPrice() %></td>
						<td class="count"><span class="reduce"></span> <input
							class="count-input" type="text" value="1" name="shu<%=i%>"/> <span class="add">+</span>
						</td>
						<td class="subtotal"><%=product1.getPrice() %></td>
						<td class="operation">
							<span class="delete"><a href="<%=request.getContextPath()%>/ProductServlet?action=deleteCat&id=<%=i%>" onclick="return confirm('是否删除？')">删除</a></span>
							<span class="shoucang"><a href="<%=request.getContextPath()%>/FavoriteServlet?action=addFav&proId=<%=product1.getPro_id()%>">移入收藏夹</a></span>
						</td>
					</tr>
					<%
						}
					}
					%>
				</tbody>
			</table>
			<div class="foot" id="foot">
				<label class="fl select-all"> <input type="checkbox"
					class="check-all check" />&nbsp;&nbsp;全选
				</label> <a class="fl delete" id="deleteAll" href="<%=request.getContextPath()%>/ProductServlet?action=deleteAll">删除</a>
				<div class="fr closing" onclick="getTotal();">
					<a href="<%=request.getContextPath() %>/ProductServlet?action=quan" class="btn btn-success">继续购物</a>
					<input type="submit" class="btn btn-success" value="结算">
				</div>
				<input type="hidden" id="cartTotalPrice" />
				<div class="fr total">
					合计：￥<span id="priceTotal">0.00</span>
				</div>
				<div class="fr selected" id="selected">
					已选商品<span id="selectedTotal">0</span>件
				</div>
			</div>
			</form>
		</div>
	</div>
</body>
<script type="text/javascript">
<%
	String str = (String)session.getAttribute("user");
	if (session.getAttribute("user") != null) {
%>
document.getElementById("huanying").innerHTML = "欢迎光临，<%=str%>";
<%
	} else {
%>
document.getElementById("huanying").innerHTML = "欢迎光临，游客";
<%
	}
%>
</script>
</html>